import request from '@/utils/request';

export async function getCustomComplaintByPage(params: any) {
  return request('/api/quality/getCustomComplaintByPage', {
    method: 'POST',
    data: params,
  });
}

export async function addCustomComplaint(params: any) {
  return request('/api/quality/addCustomComplaint', {
    method: 'POST',
    data: params,
  });
}

export async function updateCustomComplaint(params: any) {
  return request('/api/quality/updateCustomComplaint', {
    method: 'POST',
    data: params,
  });
}

export async function delCustomComplaint(params: any) {
  return request('/api/quality/delCustomComplaint', {
    method: 'POST',
    params: {
      id: params,
    },
  });
}

export async function exportCustomComplaint(params: any) {
  return request('/api/quality/exportCustomComplaint', {
    method: 'POST',
    data: params,
    responseType: 'blob',
  });
}

//获取项目名称和编号/api/project/getProjectNameAndCodeSimp
export async function getProjectNameAndCodeSimp() {
  return request('/api/project/getProjectNameAndCodeSimp', {
    method: 'POST',
  });
}

//获取客户/api/basicData/getCustomerByPage
export async function getCustomerByPage(params: any) {
  return request('/api/basicData/getCustomerByPage', {
    method: 'POST',
    data: params,
  });
}

//根据ID查看投诉信息/api/quality/getCustomComplaintById
export async function getCustomComplaintById(params: any) {
  return request('/api/quality/getCustomComplaintById', {
    method: 'POST',
    params: {
      id: params,
    },
  });
}

///api/quality/addCustomComplaintByQm
export async function addCustomComplaintByQm(params: any) {
  return request('/api/quality/addCustomComplaintByQm', {
    method: 'POST',
    requestType: 'form',
    data: params.problemPicFile,
    headers: {
      'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryX72QZDdfwlF5U73J',
    },
    params: {
      bugCount: params.bugCount,
      customerName: params.customerName,
      infoId: params.infoId,
      problemTextDes: params.problemTextDes,
      responsorId: params.responsor,
      tempSolution: params.tempSolution,
      makerId: params.maker,
      makerTime: params.makerTime,
      problemType: params.problemType,
    },
  });
}

///api/project/getUsersByInfoId获取项目负责人
export async function getUsersByInfoId(params: any) {
  return request('/api/project/getUsersByInfoId', {
    method: 'POST',
    params: {
      infoId: params,
    },
  });
}

///api/quality/submitCustomComplaint
export async function submitCustomComplaint(params: any) {
  return request('/api/quality/submitCustomComplaint', {
    method: 'POST',
    params: {
      complaintId: params,
    },
  });
}

//api/quality/shutdownCustomComplaint
export async function shutdownCustomComplaint(params: any) {
  return request('/api/quality/shutdownCustomComplaint', {
    method: 'POST',
    params: {
      finishTime: params.finishTime,
      complaintId: params.complaintId,
    },
  });
}

///api/quality/handleCustomComplaint
export async function handleCustomComplaint(params: any) {
  return request('/api/quality/handleCustomComplaint', {
    method: 'POST',
    requestType: 'form',
    data: params.improvementFile,
    headers: {
      'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryX72QZDdfwlF5U73J',
    },
    params: {
      complaintId: params.id,
      reasonAnalysis: params.reasonAnalysis,
    },
  });
}

///api/quality/analyzeCustomComplaintByQm
export async function analyzeCustomComplaintByQm(params: any) {
  return request('/api/quality/analyzeCustomComplaintByQm', {
    method: 'POST',
    params: {
      baseReasonAnalysis: params.baseReasonAnalysis,
      complaintId: params.complaintId,
      improvementText: params.improvementText,
    },
  });
}

///api/quality/getFilePreviewUrl
export async function getFilePreviewUrl(params: any) {
  return request('/api/quality/getFilePreviewUrl', {
    method: 'POST',
    params: {
      customComplaintId: params.customComplaintId,
      state: params.state,
    },
  });
}

///api/quility/getComplaintFileInfoByPageAndCP
export async function getComplaintFileInfoByPageAndCP(params: any) {
  return request('/api/quility/getComplaintFileInfoByPageAndCP', {
    method: 'POST',
    data: params,
  });
}

///api/quality/delComplaintFileInfo
export async function delComplaintFileInfo(params: any) {
  return request('/api/quality/delComplaintFileInfo', {
    method: 'POST',
    data: params,
  });
}

///api/quality/addComplaintFileInfo
export async function addComplaintFileInfo(params: any) {
  return request('/api/quality/addComplaintFileInfo', {
    method: 'POST',
    requestType: 'form',
    data: params.problemPicFile,
    headers: {
      'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryX72QZDdfwlF5U73J',
    },
    params: {
      complaintId: params.complaintId,
      state: params.state,
    },
  });
}

export default {
  getCustomComplaintByPage,
  addCustomComplaint,
  updateCustomComplaint,
  delCustomComplaint,
  exportCustomComplaint,
};
